function log(v) {
    console.log(v)
}
function api_url(api){
    return "/API/"+api
}
function api_check(response=null){
    var r=response;
    if(!r){
        msg("null response")
        return false
    }
    try{

        if(typeof(r)!="object"){
            r = JSON.parse(response)
        }
        // response={data:data,code:code,desc:desc}

        if(!r){
            info("see log,the response strange")
        }
        if(!r.data || !r.desc){
            info("see log :response not right")
        }else if(parseInt(r.code)==0) return r.data
        else{
            info("code:"+r.code+" desc:"+r.desc)
        }

    }catch (e) {
        log(e)
        info("api_check_exception:"+e)
    }
    return null
}
function info(e="def_info") {
    if (typeof(e)=="object"){
        e = JSON.stringify(e)
    }
    layer.open({
            title: '调试信息'
            , content:e
        ,skin: 'layui-layer-lan'
        });
}
function msg(msg="msg",t=2){
    t*=1000
    layer.msg(msg,{time:t})
}

    layui.use(['form'],function () {
        var form = layui.form
        form.render()
    })


function apipost(api=null,data=null,react=null) {

    if(!data || !react || !api){
        msg("not complete")
    }else{
        $.post(api_url(api),{data:JSON.stringify(data)},function (r) {


            ret = api_check(r)

            if(ret){
                 react(ret)
            }
        })
    }
}